
// Source File Name:   ENXPImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.ENXP;
import com.sunwayhorizo.health.hl7.datatypes.SET_CS;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;


//            STCommonImpl, ANYImpl, BLImpl, CSImpl,
//            NullFlavorImpl, SETCommonImpl, SET_CSImpl, TYPEImpl

public class ENXPImpl extends STCommonImpl
    implements ENXP
{

    public static final String RCS_ID = "$Header: ENXPImpl.java 1.0 2006/09/16 09:24:02 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: ENXPImpl.java 1.0 2006/09/16 09:24:02 amchanda noship $", "com.sunwayhorizo.health.hl7.datatypes.common");
    protected final CS _partType;
    protected final SET_CS _qualifier;
    private static final String QUALIFIER = "qualifier";
    private static final String PART_TYPE = "partType";
    
    private static final ENXP nullNI = new ENXPImpl(CSImpl.valueOf("NI"));
    private static final ENXP nullOTH = new ENXPImpl(CSImpl.valueOf("OTH"));
    private static final ENXP nullNINF = new ENXPImpl(CSImpl.valueOf("NINF"));
    private static final ENXP nullPINF = new ENXPImpl(CSImpl.valueOf("PINF"));
    private static final ENXP nullUNK = new ENXPImpl(CSImpl.valueOf("UNK"));
    private static final ENXP nullASKU = new ENXPImpl(CSImpl.valueOf("ASKU"));
    private static final ENXP nullNAV = new ENXPImpl(CSImpl.valueOf("NAV"));
    private static final ENXP nullMSK = new ENXPImpl(CSImpl.valueOf("MSK"));
    private static final ENXP nullNA = new ENXPImpl(CSImpl.valueOf("NA"));
    private static final ENXP nullNASK = new ENXPImpl(CSImpl.valueOf("NASK"));

    public static ENXP valueOf(String s, CS cs, SET_CS set_cs)
    {
        if(s == null || s.length() == 0)
            throw ANYImpl.newNullException("ENXP", "valueOf", "value");
        else
            return new ENXPImpl(s, cs, set_cs);
    }

    public static ENXP nullENXP()
    {
        return new ENXPImpl(NullFlavorImpl.NI);
    }

    protected ENXPImpl(String s, CS cs, SET_CS set_cs)
    {
        super(s);
        _partType = cs;
        _qualifier = set_cs;
    }

    protected ENXPImpl(CS cs)
    {
        super(cs);
        _partType = CSImpl.nullCS(NullFlavorImpl.NI);
        _qualifier = SET_CSImpl.nullSET_CS(NullFlavorImpl.NI);
    }

    public CS partType()
    {
        return _partType;
    }

    public SET_CS qualifier()
    {
        return _qualifier;
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.ENXP;
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof ENXP))
            return BLImpl.FALSE;
        ENXP enxp = (ENXP)any;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            BL bl = BLImpl.valueOf(stringValue().equals(enxp.stringValue()));
            bl = partType().isNull().isFalse() ? bl.and(partType().equal(enxp.partType())) : bl.and(enxp.partType().isNull());
            bl = qualifier().isNull().isFalse() ? bl.and(qualifier().equal(enxp.qualifier())) : bl.and(enxp.qualifier().isNull());
            return bl;
        }
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
        {
            i = 37 * i + _value.hashCode();
            i = 37 * i + (_partType.isNull().isTrue() ? 0 : _partType.hashCode());
            i = 37 * i + (_qualifier.isNull().isTrue() ? 0 : _qualifier.hashCode());
        }
        return i;
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = null;
//            if(partType() != null && partType().isNull().isFalse())
//            {
//                if(partType().code().stringValue().equals("FAM"))
//                    xmlelement = (XMLElement)xmldocument.createElement("family");
//                if(partType().code().stringValue().equals("GIV"))
//                    xmlelement = (XMLElement)xmldocument.createElement("given");
//                if(partType().code().stringValue().equals("PFX"))
//                    xmlelement = (XMLElement)xmldocument.createElement("prefix");
//                if(partType().code().stringValue().equals("SFX"))
//                    xmlelement = (XMLElement)xmldocument.createElement("suffix");
//                if(partType().code().stringValue().equals("DEL"))
//                    xmlelement = (XMLElement)xmldocument.createElement("delimiter");
//                if(xmlelement != null)
//                {
//                    xmlelement.setAttribute("partType", partType().code().stringValue());
//                    xmlelement.setAttribute("encoding", "TXT");
//                    String s1 = stringValue();
//                    if(s1 != null)
//                    {
//                        org.w3c.dom.Text text = xmldocument.createTextNode(s1);
//                        xmlelement.appendChild(text);
//                    }
//                    if(qualifier() != null && qualifier().isNull().isFalse())
//                    {
//                        XMLNode axmlnode[] = ((SET_CSImpl)qualifier()).writeXML(xmldocument, "qualifier");
//                        xmlelement.setAttribute("qualifier", axmlnode[0].getAttributes().getNamedItem("code").getNodeValue());
//                    }
//                }
//            }
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static ENXP nullENXP(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

	public byte[] byteArray() {
		// TODO Auto-generated method stub
		return null;
	}

}
